package com.jzlw.huozhuduan.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;


import com.jzlw.huozhuduan.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyPhotoDialog extends Dialog {

    @BindView(R.id.tv_btn_album)
    TextView tvBtnAlbum;
    @BindView(R.id.tv_btn_photograph)
    TextView tvBtnPhotograph;
    @BindView(R.id.tv_btn_cancel)
    TextView tvBtnCancel;
    @BindView(R.id.ll_01)
    LinearLayout ll01;
    private View view;
    private Context context;
    private Window window;

    public MyPhotoDialog(@NonNull Context context) {
        super(context,R.style.Theme_Light_PayDialog);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = LayoutInflater.from(context).inflate(R.layout.dialog_my_photo, null);
        setContentView(view);
        ButterKnife.bind(this, view);
        window = getWindow();
        initWindow();


    }


    private void initWindow() {
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.AnimBottomOut); // 添加动画
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    private View.OnClickListener photoOnClickListener;
    private View.OnClickListener albumOnClickListener;

    public void setPhotoDialog(View.OnClickListener photoOnClickListener, View.OnClickListener albumOnClickListener) {
        this.photoOnClickListener = photoOnClickListener;
        this.albumOnClickListener = albumOnClickListener;
    }


    @OnClick({R.id.tv_btn_album, R.id.tv_btn_photograph, R.id.tv_btn_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_btn_album:
                dismiss();
                if (albumOnClickListener != null) {
                    albumOnClickListener.onClick(view);
                }
                break;
            case R.id.tv_btn_photograph:
                dismiss();
                if (photoOnClickListener != null) {
                    photoOnClickListener.onClick(view);
                }
                break;
            case R.id.tv_btn_cancel:
                dismiss();
                if (photoOnClickListener == null || albumOnClickListener == null){
                    assert photoOnClickListener != null;
                    photoOnClickListener.onClick(null);
                }
                break;
            default:
                break;
        }
    }
}
